package org.fas.utils
{
	import flash.display.Sprite;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class FuGeom
	{
		public function FuGeom()
		{
		}
		public static function drawCircleAngle(_drawer:Sprite,_x:Number,_y:Number,_radius:Number,_fromAngle:Number,_toAngle:Number):void{
			var center:Point=new Point(_x,_y);//Center of Circle 
			var angle:Number=_toAngle-_fromAngle;//Angle of Circle
			var startFrom:Number=_fromAngle;//Angle of Start
			var r:Number= _radius;//Radius
               
			angle=Math.abs(angle) > 360?360:angle;
			var n:Number=Math.ceil(Math.abs(angle) / 45);
			var angleA:Number=angle / n;
			angleA=angleA * Math.PI / 180;
			startFrom=startFrom * Math.PI / 180;
			
			_drawer.graphics.moveTo(center.x ,center.y);
			_drawer.graphics.lineTo(center.x + r * Math.cos(startFrom),center.y + r * Math.sin(startFrom));
			
			for (var i:int=1; i <= n; i++) {
			        startFrom+= angleA;
			        var angleMid:Number=startFrom - angleA / 2;
			        var bx:Number = center.x + r /Math.cos(angleA / 2) * Math.cos(angleMid)
			        var by:Number = center.y + r / Math.cos(angleA / 2) * Math.sin(angleMid);
			        var cx:Number = center.x + r * Math.cos(startFrom);
			        var cy:Number = center.y + r * Math.sin(startFrom);
			        _drawer.graphics.curveTo(bx,by,cx,cy);
			}
			_drawer.graphics.lineTo(center.x ,center.y);
		}
		/**
		 *create background for MouseEvent or only to see
		 * @return 
		 * 
		 */		
		public static function DrawBg(_ob:Sprite,_w:Number=400,_h:Number=400,_color:Number=0xFFFFFF,_alpha:Number=0):void{
			var _bg:Sprite = new Sprite();
			_bg.graphics.beginFill(_color,_alpha);
			_bg.graphics.drawRect(0,0,_w,_h);
			_bg.graphics.endFill();
			_ob.addChildAt(_bg,0);
		}
		public static function DrawCircle(_ob:Sprite,_centerX:Number=0,_centerY:Number=0,_radius:Number=10,_color:Number=0x00FF00,_alpha:Number=1):void{
			_ob.graphics.beginFill(_color,_alpha);
			_ob.graphics.drawCircle(_centerX,_centerY,_radius);
			_ob.graphics.endFill();
		}
		public static function DrawRectByCenter(_ob:Sprite,_centerX:Number=0,_centerY:Number=0,_width:Number=10,_height:Number=10,_color:Number=0x00FF00,_alpha:Number=1):void{
			_ob.graphics.beginFill(_color,_alpha);
			_ob.graphics.drawRect(_centerX-_width/2,_centerY-_height/2,_width,_height);
			_ob.graphics.endFill();
		}
		public static function DrawRect(_ob:Sprite,_x:Number=0,_y:Number=0,_width:Number=100,_height:Number=100,_colorFill:uint=0x111111,_alphaFill:Number=1,_colorLine:uint=0xFF9900,_alphaLine:Number=1,_thickness:Number=0):void{
			_ob.graphics.clear();
			_ob.graphics.beginFill(_colorFill,_alphaFill);
			_ob.graphics.lineStyle(_thickness,_colorLine,_alphaLine);
			_ob.graphics.drawRect(_x,_y,_width,_height);
			_ob.graphics.endFill();
		}
		public static function fitRectIn(_ob:Sprite):void{
			var _rect:Rectangle = _ob.getRect(_ob.parent);
			_ob.graphics.lineStyle(1,0xFF9900,0.6);
			_ob.graphics.drawRect(_rect.x,_rect.y,_rect.width,_rect.height);
		}
		public static function getGlowFilter(_color:uint=0xFF9900):GlowFilter {
            var color:Number = _color;
            var alpha:Number = 1;
            var blurX:Number = 20;
            var blurY:Number = 20;
            var strength:Number = 2;
            var inner:Boolean = false;
            var knockout:Boolean = false;
            var quality:Number = BitmapFilterQuality.LOW;
            return new GlowFilter(color,
                                  alpha,
                                  blurX,
                                  blurY,
                                  strength,
                                  quality,
                                  inner,
                                  knockout);
        }
	}
}